<?php

class LoginController extends Zend_Controller_Action {
    private $sessionLogin;

    /**
     * Constructor
     */
    public function init() {
        $this->sessionLogin = new Zend_Session_Namespace('User');
        if(!empty($this->sessionLogin->userinfo)) {
            $this->_redirect('/');
        }
    }

    /**
     * Main Back End
     */
    public function indexAction() {
        //check login
        if ($this->_request->isPost()) {
            $arrParams = $this->_request->getParams();            
            $result = Service_Model::factory('User', 'getUserInfo', $arrParams, 'frontend');
            if (!empty($result)) {
                if ($result['acc_pass'] == md5($arrParams['passwd'])) {
                    $this->sessionLogin = new Zend_Session_Namespace('User');
                    $this->sessionLogin->userinfo = $result;
                    $this->sessionLogin->userinfo['acc_pass'] = NULL;                    
                    echo json_encode(array('flaglogin' => true));
                    exit();
                }
                else {
                    $errorFlag = true;
                }
            }
            else {
                $errorFlag = true;
            }
            if ($errorFlag) {
                echo json_encode(array('flaglogin' => false));
                exit;
            }
        }
        //End If
    }

    
}

